package com.imooc.beanannotation.javabased;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;

@Configuration
@ImportResource("classpath:config.xml")
public class StoreConfig {
	// 4.6 基于Java的容器注解 @ImportResource和@Value
/*	@Value(value = "${jdbc.url}")
	private String url;
	@Value(value = "${jdbc.username}")
	private String username;
	@Value(value = "${jdbc.password}")
	private String password;
	
	@Bean
	public MyDriverManager myDriverManager() {
		return new MyDriverManager(url, username, password);
		
	}*/
	
	// 4.5 基于Java的容器注解 @Bean
	
/*	//@Bean
	//@Bean(name="store")
	@Bean(name="stringstore", initMethod="init", destroyMethod="destory")
	public  Store getStringStore() {
		return new StringStore();
	}*/
	
	// 4.7 基于Java的容器注解 @Bean 和 @Scope
/*	
	@Bean(name="stringstore",initMethod="init", destroyMethod="destory")
	// 单例 @Scope(value="singleton")
	// prototype 原型
	@Scope(value="prototype",proxyMode=ScopedProxyMode.TARGET_CLASS)
	public Store getStringStore() {
		
		return new StringStore();
	}*/
	
	// 4.8 基于Java的容器注解之 基于泛型的自动装配
	@Autowired
	private Store<String> s1;
	
	@Autowired
	private Store<Integer> s2;
	
	@Bean
	public StringStore stringStore() {
		return new StringStore();
	}
	
	@Bean
	public IntegerStore integerStore() {
		return new IntegerStore();
	}
	
	@Bean(name="stringStoreTest")
	public Store stringStoreTest() {
		System.out.println("s1:" + s1.getClass().getName());
		System.out.println("s2:" + s2.getClass().getName());
		
		return new StringStore();
		
	}
}
